package com.lottery.ruok.lottrey.chat.event.manager;

import io.rong.imkit.RongIM;
import io.rong.imkit.manager.IUnReadMessageObserver;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;

/**
 * 未读信息管理者
 */
public class UnReadMessageManager {
    private static UnReadMessageManager unReadMessageManager;

    public static synchronized UnReadMessageManager getInstance() {
        if (unReadMessageManager == null) {
            unReadMessageManager = new UnReadMessageManager();
        }
        return unReadMessageManager;
    }

    /**
     * 获取所有私聊未读消息
     *
     * @param callback
     */
    public void getPrivateTotalUnreadCount(RongIMClient.ResultCallback<Integer> callback) {
        RongIM.getInstance().getUnreadCount(callback, Conversation.ConversationType.PRIVATE);
    }

    /**
     * 获取某一个私人聊天未读消息
     *
     * @param callback
     * @param targetId
     */
    public void getPrivateUnreadCount(RongIMClient.ResultCallback<Integer> callback, String targetId) {
        RongIM.getInstance().getUnreadCount(Conversation.ConversationType.PRIVATE, targetId, callback);
    }

    /**
     * register 所有私人聊天未读消息监听
     */
    public void registerPrivateUnReadMessageCountChangedObserver(IUnReadMessageObserver iUnReadMessageObserver) {
        RongIM.getInstance().addUnReadMessageCountChangedObserver(iUnReadMessageObserver, Conversation.ConversationType.PRIVATE);
    }

    /**
     * 移除所有私人未读消息监听
     *
     * @param iUnReadMessageObserver
     */
    public void unRegisterPrivateUnReadMessageCountChangedObserver(IUnReadMessageObserver iUnReadMessageObserver) {
        RongIM.getInstance().removeUnReadMessageCountChangedObserver(iUnReadMessageObserver);

    }

}
